home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 5.1 KB | 154 lines | [TEXT/CCL2] |
- ;;; select-icon-button.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;; Select icon button is a specialized dialog item to display a
- ;;; button with a selected icon. When the button is pressed, a pop
- ;;; up view is displayed presenting a palette of icons to choose from.
- ;;; The user can choose an icon by moving the mouse to it. The selected
- ;;; icon becomes the button's face when the mouse is released.
- ;;;
- ;;; USE:
- ;;;
- ;;; select-icon-button - dialog item object class
- ;;; :selected-icon - number or nickname of an icon
- ;;; (see pop-up-select-icon-view for more info)
- ;;;
- ;;; selected-icon - return the number or nickname of the selected icon
- ;;; set-selected-icon - set the number or nickname of the selected icon
- ;;;
- ;;; HISTORY:
- ;;;
- ;;; 7/23/92 Created. - PM
- ;;;
-
- (in-package :ccl)
-
- (require :pop-up-select-icon-view)
- (require :GWorld-view-extensions)
-
- (export '(select-icon-button selected-icon set-selected-icon)
- :ccl)
-
-
- (defclass select-icon-button (pop-up-select-icon-view dialog-item)
- ((selected-icon :initarg :selected-icon :accessor icon-num)
- )
- (:default-initargs
- :selected-icon 0
- )
- )
-
-
- (defmethod initialize-instance ((view select-icon-button) &rest initargs)
- (apply #'call-next-method view initargs)
- (set-view-size view
- (+ (point-h (i-size view)) 12)
- (+ (point-v (i-size view)) 6))
- (if (symbolp (icon-num view))
- (set-selected-icon view (icon-num view)))
- )
-
-
- (defmethod view-draw-contents ((view select-icon-button))
- (let ((right (point-h (view-size view)))
- (bottom (point-v (view-size view))))
- (with-GWorld-no-colorization (view 0 0 right bottom)
- (with-back-color (or (part-color view :background) *white-color*)
- (with-fore-color (or (part-color view :shadow) *black-color*)
- (rlet ((r :rect :topleft #@(2 2) :bottomright (view-size view)))
- (#_PaintRect r)))
- (rlet ((r :rect
- :topleft #@(0 0)
- :bottomright (subtract-points (view-size view) #@(2 2))))
- (#_EraseRect r)
- (with-fore-color (or (part-color view :frame) *black-color*)
- (#_FrameRect r)))
- (rlet ((r :rect
- :topleft #@(2 2)
- :bottomright (add-points #@(2 2) (i-size view))))
- (with-fore-color (or (part-color view :foreground) *black-color*)
- (if (color-p view)
- (#_plotCicon r (nth (icon-num view) (icons view)))
- (#_ploticon r (nth (icon-num view) (icons view)))))) ))
- (draw-pop-up-triangle view) ))
-
-
- (defmethod draw-pop-up-triangle ((view select-icon-button))
- (let* ((top (- (ceiling (point-v (i-size view)) 2) 3))
- (bottom (+ top 10))
- (left (- (point-h (view-size view)) 9))
- (right (+ left 5))
- (middle (floor (+ top bottom) 2)))
- (with-focused-view view
- (with-fore-color (or (part-color view :frame) *black-color*)
- (with-port (wptr view) (setf (view-get view 'my-poly) (#_OpenPoly)))
- (#_Moveto left top)
- (#_Lineto right middle)
- (#_Lineto left bottom)
- (#_Lineto left top)
- (let ((poly (view-get view 'my-poly)))
- (with-port (wptr view) (#_ClosePoly))
- (#_PaintPoly poly)
- (#_KillPoly poly) )) )))
-
-
- (defmethod view-click-event-handler ((view select-icon-button) where)
- (declare (ignore where))
- (let ((old-item (icon-num view))
- (new-item (puv-select-icon view view)))
- (when (and new-item (not (equal old-item new-item)))
- (set-selected-icon view new-item)
- (dialog-item-action view))))
-
-
- (defmethod remove-view-from-window ((view select-icon-button))
- (call-next-method)
- (pusiv-destroy view))
-
-
- (defmethod selected-icon ((view select-icon-button))
- (let ((len (1- (length (icon-nicknames view)))))
- (if (>= len (icon-num view))
- (nth (icon-num view) (icon-nicknames view))
- (icon-num view))))
-
-
- (defmethod set-selected-icon ((view select-icon-button) n)
- (cond ((and (numberp n) (<= 0 n (1- (length (icons view)))))
- (setf (icon-num view) n)
- (invalidate-view view))
- ((member n (icon-nicknames view))
- (setf (icon-num view) (position n (icon-nicknames view)))
- (invalidate-view view))
- (t (error "Invalid icon number: ~s, supplied to select icon button." n)) ))
-
-
- (provide :select-icon-button)
-
- #|
-
- (puv-init)
- ; (puv-destroy)
-
- (setf w (make-instance 'window
- :color-p t
- :view-subviews
- (list (make-instance 'select-icon-button
- :color-p nil
- :selected-icon 'note
- :icons '((0 stop) (1 note) (2 alert))
- :icon-size #@(32 32)
- :view-position #@(20 20)
- :color-list (list :selection *orange-color*
- :foreground *brown-color*
- :background *yellow-color*
- :shadow *green-color*)))))
-
- |#